package lava.rt.linq;

import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;



public class Mocker {

    private static final String CHAR_EN="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	
	private static final Random RANDOM = new Random();
	
	public static int mock(Entity entity) {
		Map<String, Field> fieldMap = getAllDeclaredFieldMap(entity.thisClass());
	    int ret = 0;
		try {
			for (Entry<String, Field> en : fieldMap.entrySet()) {
				Field field = en.getValue();
				
				field.setAccessible(true);
				
				ret++;
				if(field.getType().equals(String.class)) {
					int dataLength=1;
					String val=createRandomEn(RANDOM,dataLength);
					field.set(entity, val);
				}else if(field.getType().equals(Integer.class)) {
					field.set(entity, RANDOM.nextInt(10000));
				}else if(field.getType().equals(Double.class)) {
					field.set(entity, RANDOM.nextGaussian());
				}else if(field.getType().equals(Float.class)) {
					field.set(entity, RANDOM.nextFloat());
				}else if(field.getType().equals(BigDecimal.class)) {
					field.set(entity, new BigDecimal(RANDOM.nextGaussian()));
				}else if(field.getType().equals(Date.class)) {
					field.set(entity,new Date());
				}else if(field.getType().equals(Timestamp.class)) {
					field.set(entity,new Timestamp(System.currentTimeMillis()));
				}
				else {
					ret--;
				}
				
				

			}
		} catch (Exception e) {}
        return ret;		
	}
	
	private static Map<String, Field> getAllDeclaredFieldMap(Class<? extends Entity> thisClass) {
		// TODO Auto-generated method stub
		return null;
	}

	private static String createRandomEn(Random random,int dataLength) {
		// TODO Auto-generated method stub
	     StringBuffer ret=new StringBuffer();
	     for(int i=0;i<dataLength;i++){
	       int number=random.nextInt(62);
	       ret.append(CHAR_EN.charAt(number));
	     }
	     return ret.toString();
	}
	
	
}
